package controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Doctor;
import service.DoctorService;


import java.util.List;

@Api(tags = "医生管理接口")
@RestController
@CrossOrigin
@RequestMapping("/doctors")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @ApiOperation(value = "添加医生", notes = "根据Doctor对象添加医生信息")
    @PostMapping("/add")
    public int addDoctor(@ApiParam(value = "医生实体", required = true) @RequestBody Doctor doctor) {
        return doctorService.insertDoctor(doctor);
    }

    @ApiOperation(value = "删除医生", notes = "根据ID删除医生信息")
    @DeleteMapping("/{id}")
    public int deleteDoctor(@ApiParam(value = "医生ID", required = true) @PathVariable("id") String docId) {
        return doctorService.deleteDoctorById(docId);
    }

    @ApiOperation(value = "更新医生信息", notes = "根据Doctor对象更新医生信息")
    @PutMapping("/update")
    public int updateDoctor(@ApiParam(value = "医生实体", required = true) @RequestBody Doctor doctor) {
        return doctorService.updateDoctor(doctor);
    }

    @ApiOperation(value = "获取医生信息", notes = "根据ID获取医生信息")
    @GetMapping("/{id}")
    public Doctor getDoctor(@ApiParam(value = "医生ID", required = true) @PathVariable("id") String docId) {
        return doctorService.selectDoctorById(docId);
    }

    @ApiOperation(value = "获取所有医生", notes = "获取所有医生列表")
    @GetMapping("/list")
    public List<Doctor> getAllDoctors() {
        return doctorService.selectAllDoctors();
    }
    @ApiOperation(value = "根据姓名查询医生", notes = "精确/模糊匹配医生姓名")
    @GetMapping("/searchByName")
    public List<Doctor> searchDoctorsByName(
            @ApiParam(value = "医生姓名", required = true)
            @RequestParam String docName
    ) {
        return doctorService.searchByName(docName);
    }
}

